package main

import (
	"google.golang.org/grpc"
	"log"
	"mytest/gokit/module/hello/endpoint"
	"mytest/gokit/module/hello/service"
	"mytest/gokit/module/hello/transport"
	"mytest/gokit/proto/hello"
	"net"
)

const (
	ServiceHostPort = "0.0.0.0:9902"
)

func main() {

	l, err := net.Listen("tcp", ServiceHostPort)
	if err != nil {
		log.Fatalf("Failed to listen: %v", err)
	}

	//创建hello服务
	helloService := service.NewService()

	//创建hello服务节点
	endpoints := endpoint.NewEndpoints(helloService)

	//创建hello的grpc服务
	grpcSrv := transport.MakeGRPCServer(endpoints)

	s := grpc.NewServer()
	//服务注册
	proto.RegisterHelloServer(s, grpcSrv)

	log.Println("Listen on " + ServiceHostPort)
	if err := s.Serve(l); err != nil {
		log.Fatalf("Failed to serve: %v", err)
	}
}
